package org.vincen.helloworld.rubbish;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * 在当前工程下，搜索并加载properties或者xml配置文件。
 * @author vincen
 */
public class R20121115{
	
    public String classpathResource(String fileName) {
        InputStream is = null;
        StringBuilder builder = new StringBuilder();
        BufferedReader reader = null;
        String line = null;
        is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
        reader = new BufferedReader(new InputStreamReader(is));
        try {
            while((line = reader.readLine()) != null){
            	builder.append(line).append("\n");
            }
            is.close();
        }catch(IOException e){
            e.printStackTrace();
        }
        return builder.toString();
    }

    public static void main(String args[]) {
        R20121115 a = new R20121115();
        String s = a.classpathResource("config.xml");
        System.out.println(s);
    }
}
